package leetcode;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class LC26 {
    public static void main(String[] args) {

    }
    public ListNode detectCycle(ListNode head) {
        Set<ListNode> map = new HashSet<>();
        while(head != null){
            if (map.contains(head)) return head;
            map.add(head);
            head = head.next;
        }
        return null;
    }
}
